package com.ruoyi.project.platform.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.platform.domain.RRobot;
import com.ruoyi.project.platform.service.IRRobotService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 机器人Controller
 * 
 * @author ruoyi
 * @date 2020-07-27
 */
@RestController
@RequestMapping("/platform/robot")
public class RRobotController extends BaseController
{
    @Autowired
    private IRRobotService rRobotService;

    /**
     * 查询机器人列表
     */
    @PreAuthorize("@ss.hasPermi('platform:robot:list')")
    @GetMapping("/list")
    public TableDataInfo list(RRobot rRobot)
    {
        startPage();
        List<RRobot> list = rRobotService.selectRRobotList(rRobot);
        return getDataTable(list);
    }

    /**
     * 导出机器人列表
     */
    @PreAuthorize("@ss.hasPermi('platform:robot:export')")
    @Log(title = "机器人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RRobot rRobot)
    {
        List<RRobot> list = rRobotService.selectRRobotList(rRobot);
        ExcelUtil<RRobot> util = new ExcelUtil<RRobot>(RRobot.class);
        return util.exportExcel(list, "robot");
    }

    /**
     * 获取机器人详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:robot:query')")
    @GetMapping(value = "/{robotId}")
    public AjaxResult getInfo(@PathVariable("robotId") Long robotId)
    {
        return AjaxResult.success(rRobotService.selectRRobotById(robotId));
    }

    /**
     * 新增机器人
     */
    @PreAuthorize("@ss.hasPermi('platform:robot:add')")
    @Log(title = "机器人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RRobot rRobot)
    {
        return toAjax(rRobotService.insertRRobot(rRobot));
    }

    /**
     * 修改机器人
     */
    @PreAuthorize("@ss.hasPermi('platform:robot:edit')")
    @Log(title = "机器人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RRobot rRobot)
    {
        return toAjax(rRobotService.updateRRobot(rRobot));
    }

    /**
     * 删除机器人
     */
    @PreAuthorize("@ss.hasPermi('platform:robot:remove')")
    @Log(title = "机器人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{robotIds}")
    public AjaxResult remove(@PathVariable Long[] robotIds)
    {
        return toAjax(rRobotService.deleteRRobotByIds(robotIds));
    }
}
